<?php
/**
 * Created by PhpStorm.
 * User: guokunsheng
 * Date: 2019/2/28
 * Time: 10:11
 */

namespace app\web\controller;

use app\common\model\Article;
use think\Controller;

/**
 * 运势文章
 * Class FortuneArticle
 * @package app\web\controller
 */
class FortuneArticle extends Controller
{
    /**
     * 获取周月年文章
     * @return \think\response\Json
     * @throws \app\common\lib\exception\ApiException
     */
    public function index()
    {
        $type = input('type/s', 'week');
        $sign = input('sign/d', 1);

        if (!in_array($type, ['week', 'month', 'year']))
        {
            $type = 'week';
        }
        if($sign < 1 || $sign > 12)
        {
            $sign = 1;
        }

        $data = (new Article())->getFortune($type, $sign);

        return show(config('code.success'), '加载成功', $data);
    }
}
